﻿#region itdc

/************************************************************************
*Copyright(C) 2015 by qsgy
 *All rights reserved. 
 *FileName:     $safeitemname$
 *Author:       oyh
 *Version:      
 *UnityVersion：
 *Date:   $time$      
 *Description:    
 *History: 
************************************************************************/
#endregion
using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// 说话结束自销毁
/// </summary>
public class SpeakDialog :NextRunner {
    public Text speak;
    
    [Tooltip("要说的话。段落"),Multiline(3)]
    public string[] words;
    [Tooltip("5个字读几秒")]
    public float readSpeed = 2f;
    public float blackTime = 1f;


    private IEnumerator StartShow()
    {
        yield return 1;
        for (int i = 0; i < words.Length; i++)
        {
            speak.text = "";
            speak.DOText(words[i], words[i].Length/5f*readSpeed,false);
            yield return new WaitForSeconds(words[i].Length / 5f * readSpeed + blackTime);
        }
        Destroy(gameObject);
     
       
    }

    public void OnEnable()
    {
        StartCoroutine(StartShow());
    }

    private void OnDestroy()
    {

        StopCoroutine("StartShow");
    }

    private void OnDisable()
    {
        StopCoroutine("StartShow");

    }
}
